home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 965 b | 62 lines | [TEXT/MPS ] |
- #include <stream.h>
- #include <stdarg.h>
-
- //extern void exit(int);
-
- void error(const char *fmt ...)
- {
- va_list ap;
- va_start(ap, fmt);
- char ch;
- while (ch = *fmt++)
- if (ch != '%')
- cerr.put(ch);
- else
- switch (ch = *fmt++)
- {
- case '%':
- cerr.put('%');
- break;
- case 's':
- {
- char *s = va_arg(ap, char*);
- cerr << s;
- }
- break;
- case 'd':
- {
- int s = va_arg(ap, int);
- cerr << s;
- }
- break;
- case 'f':
- {
- float s = va_arg(ap, float);
- cerr << s;
- }
- break;
- case 'c':
- {
- int s = va_arg(ap, int);
- cerr.put(s);
- }
- break;
- default:
- cerr << "\nunknown % sequence: %" << chr (ch) << "\n";
- break;
- }
- va_end(ap);
- //exit(1);
- }
-
-
- main()
- {
- int theInt = 23;
- char theChar = 'A';
- char * str = "words";
- float f1 = 1.01;
- float f2 = 2.02;
- float f3 = 3.03;
- error("Try %d or %c %d %d %d %s end",theInt,theChar,(int)f1,(int)f2,(int)f3,str);
- }